package com.dy.dept.controller;


import com.dy.dept.entity.Dept;
import com.dy.dept.entity.Deptinfo;
import com.dy.dept.service.IDeptinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dy
 * @since 2022-03-22
 */
@RestController
@RequestMapping("/deptinfo")
public class DeptinfoController {
    @Autowired
    private IDeptinfoService deptinfoService;

    @PostMapping("/insert/{role}/{id}")
    public boolean insertDeptInfoByDept(@PathVariable("id") Integer id){
        Dept dept = new Dept();
        dept.setDeptId(id);
        Deptinfo deptinfo = new Deptinfo();
        deptinfo.setInfoJob("中级程序员");
        deptinfo.setInfoSalary(12000);
        Deptinfo deptinfo1 = new Deptinfo();
        deptinfo1.setInfoSalary(21500);
        deptinfo1.setInfoJob("高级程序员");
        List<Deptinfo> list = new ArrayList<>();
        list.add(deptinfo);
        list.add(deptinfo1);
        dept.setDeptInfoList(list);
        return deptinfoService.insertDeptInfoByDept(dept);
    }

    @PostMapping("/postform/{role}")
    public boolean insertOneDeptinfo(Deptinfo deptinfo){
        System.out.println(deptinfo);
        boolean save = deptinfoService.save(deptinfo);
        return save;
    }
}
